package com.oyb.entity;

import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode;

import javax.servlet.jsp.tagext.TryCatchFinally;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class Admin implements Serializable {


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    private Integer id;
    private String username;
    private String password;
    private String sex;
    private List<String> power;
    private String truename;
    private Date birthday;
    private String homepalce;
    private String jiguan;
    private String photo;

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public List<String> getPower() {
        return power;
    }

    public void setPower(List<String> power) {
        this.power = power;
    }
    public void setPower(String[] power) {
        this.power = Arrays.asList(power);
    }

    public String getTruename() {
        return truename;
    }

    public void setTruename(String truename) {
        this.truename = truename;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
    public void setBirthday(String birthday) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

            try {
                this.birthday = simpleDateFormat.parse(birthday);
            } catch (ParseException e) {
                e.printStackTrace();
            }
       

    }

    public String getHomepalce() {
        return homepalce;
    }

    public void setHomepalce(String homepalce) {
        this.homepalce = homepalce;
    }

    public String getJiguan() {
        return jiguan;
    }

    public void setJiguan(String jiguan) {
        this.jiguan = jiguan;
    }

    public synchronized void addPower(String power){
        if (this.power==null){
            this.power = new ArrayList<>();
        }
        this.power.add(power);
    }
//将集合的权限转换成字符串
    public String getPowerStr(){
        List<String> powers = this.getPower();
        String powerStr = "";
        for (String power : powers) {
            if (powerStr.length() != 0) powerStr += "-";
            powerStr += power;
        }
        return powerStr;
    }

    @Override
    public String toString() {
        return "Admin{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", sex='" + sex + '\'' +
                ", power=" + power +
                ", truename='" + truename + '\'' +
                ", birthday=" + birthday +
                ", homepalce='" + homepalce + '\'' +
                ", jiguan='" + jiguan + '\'' +
                ", photo='" + photo + '\'' +
                '}';
    }
}
